// pages/myconcern/myconcern.js
let util = require("../../utils/util.js");
var baseImgUrl = util.baseImgUrl;
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    networkStatus: true,
    loadingStatus: false,//默认加载完成，true--正在加载中
    loadgif: util.imgUrl + "loading.gif",//加载gif图
    loading: util.imgUrl + "loading.png",
    none_network: util.imgUrl + "none_network.png",

    activeIndex:'',
    scanSrc:baseImgUrl+"scan.png",
    audio_bg: baseImgUrl +"audio_bg.png",
    audio_s: baseImgUrl +"audio_s.png",
    navList:[{
        id:0,
        navName:"文章"
    }, {
        id: 1,
        navName: "达人"
      }, {
        id: 2,
        navName: "足迹"
      }, {
        id: 3,
        navName: "粉丝"
      }],
    kong_wenzhang:baseImgUrl+"kongSrc1.png",
    kong_daren: baseImgUrl + "kongSrc2.png",
    kong_zuji: baseImgUrl + "kongSrc3.png",
    kong_fensi: baseImgUrl + "kongSrc2.png",
    // 文章列表测试数据
    newslists: [{
      id: 1,
      types: 1,//新闻类型
      title: "网上下拉刷新的例子挺多的，我也用了试成功了一个，但目前发现，当本来listView内容过少不能充满父容器的时候，下拉刷新的头部",
      name: "广告",
      user_nickname: "医学护肤",
      dianji: 100,
      media: [baseImgUrl + "pic0.png", baseImgUrl + "pic0.png", baseImgUrl + "pic0.png"],
      color: true
    },
    {
      id: 2,
      types: 2,//新闻类型
      title: "网上下拉刷新的例子挺多的，我也用了试成功了一个，但目前发现，当本来listView内容过少不能充满父容器的时候，下拉刷新的头部",
      name: "广告",
      user_nickname: "医学护肤",
      dianji: 100,
      media: [baseImgUrl + "pic0.png", baseImgUrl + "pic0.png", baseImgUrl + "pic0.png"],
      color: false
    },
      {
        id: 3,
        types: 3,//新闻类型
        title: "网上下拉刷新的例子挺多的，我也用了试成功了一个，但目前发现，当本来listView内容过少不能充满父容器的时候，下拉刷新的头部",
        name: "广告",
        user_nickname: "医学护肤",
        dianji: 100,
        media: [baseImgUrl + "pic0.png", baseImgUrl + "pic0.png", baseImgUrl + "pic0.png"],
        color: true
      },
      {
        id:4,
        types: 6,//新闻类型
        title: "网上下拉刷新的例子挺多的，我也用了试成功了一个，但目前发现，当本来listView内容过少不能充满父容器的时候，下拉刷新的头部",
        name: "广告",
        user_nickname: "医学护肤",
        dianji: 100,
        media: [baseImgUrl + "/pic0.png", baseImgUrl + "/pic0.png", baseImgUrl + "/pic0.png"],
        color: false
      }],
    darenlists:[{
      id:0,
      logoSrc:baseImgUrl+"userlogo.png",
      username:"张三",
      num:10,
      followFlag:true
    }, {
        id: 1,
        logoSrc: baseImgUrl + "userlogo.png",
        username: "张三",
        num: 10,
        followFlag: true
      }, {
        id: 2,
        logoSrc: baseImgUrl + "userlogo.png",
        username: "张三",
        num: 10,
        followFlag: true
      }, {
        id: 3,
        logoSrc: baseImgUrl + "userlogo.png",
        username: "张三",
        num: 10,
        followFlag: false
      }, {
        id: 4,
        logoSrc: baseImgUrl + "userlogo.png",
        username: "张三",
        num: 10,
        followFlag: false
      }],
    visitedarr: [],//保存已读新闻的id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var thisid=options.thisid;
      var tag = options.tag;
      var that=this;
      that.setData({
        activeIndex:thisid,
        loadingStatus: true
      })

    /*********判断网络************ */
    wx.getNetworkType({
      success: function (res) {
        var networkType = res.networkType;
        if (networkType == "none" || networkType == "unknown") {
          that.setData({
            networkStatus: false
          })
        } else {
          that.setData({
            networkStatus: true,

          })
        }
      }, fail: function (err) {
        console.log("获取网络失败" + err);
        that.setData({
          networkStatus: false
        })
      }
    })

   
    wx.request({
      url: 'https://www.jikecity.xin/small/my/' + tag,  //此tag是活的  
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded" //post
      },
      success: function (res) {
        console.log("---------------res-----------------");
        console.log(res);
        that.setData({
          loadingStatus: false
        })
        if(res.data.tag == 0){
            that.setData({
              wenzhang: res.data.wenzhang,
            })
        } else if (res.data.tag == 1){
          that.setData({
            daren: res.data.daren,
          })
        } else if (res.data.tag == 2) {
          that.setData({
            zuji: res.data.zuji,
          })
        } else if (res.data.tag == 3) {
          that.setData({
            fensi: res.data.fensi,
          })
        }
      },
      fail: function (err) {
        console.log( err);
        that.setData({
          loadingStatus: true
        })
      }
    })
  },

  /*******点击顶部导航栏切换导航菜单******** */
  //文章
  clickNav0:function(e){
    console.log(e);
    var that = this;
    var thisid=e.currentTarget.id*1;
      that.setData({
        activeIndex:thisid
      })

    wx.request({
      url: util.wanzhang,  //此tag是活的  
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded" //post
      },
      success: function (res) {
        that.setData({
          wenzhang: res.data.wenzhang,
        })
      },
      fail: function (err) {
        console.log("err" + err);
      }
    })
  },

  //达人
  clickNav1: function (e) {
    console.log(e);
    console.log(util.daren);
    var that = this;
    var thisid = e.currentTarget.id * 1;
    that.setData({
      activeIndex: thisid
    })
    wx.request({
      url: util.daren,  //此tag是活的  
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded" //post
      },
      success: function (res) {
        that.setData({
          daren: res.data.daren,
        })
      },
      fail: function (err) {
        console.log("err" + err);
      }
    })
  },

  //足迹
  clickNav2: function (e) {
    console.log(e);
    var that = this;
    var thisid = e.currentTarget.id * 1;
    that.setData({
      activeIndex: thisid
    })
    wx.request({
      url: util.zuji,  //此tag是活的  
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded" //post
      },
      success: function (res) {
        that.setData({
          zuji: res.data.zuji,
        })
      },
      fail: function (err) {
        console.log("err" + err);
      }
    })
  },

  //粉丝
  clickNav3: function (e) {
    console.log(e);
    var that = this;
    var thisid = e.currentTarget.id * 1;
    that.setData({
      activeIndex: thisid
    })
    wx.request({
      url: util.fensi,  //此tag是活的  
      data: {
        openid: app.globalData.openid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded" //post
      },
      success: function (res) {
        that.setData({
          fensi: res.data.fensi,
        })
      },
      fail: function (err) {
        console.log("err" + err);
      }
    })
  },

  /**************取消关注******************* */
  quxiaoguanzhu:function(e){
    var  that=this;
    var activeIndex = that.data.activeIndex;
    var thisid=e.currentTarget.id;
    var tags = e.currentTarget.dataset.guanzhu;
    var zid = e.currentTarget.dataset.id;
    wx.showModal({
      cancelColor:"#888",
      confirmColor:"#d33a3d",
      content: '确定不再关注此人',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: 'https://www.jikecity.xin/small/my/' + tags,  //此tag是活的  
            data: {
              openid: app.globalData.openid,
              zid: zid,
            },
            method: "POST",
            header: {
              "Content-Type": "application/x-www-form-urlencoded" //post
            },
            success: function (res) {
              console.log(res);
              if(res.data.tag == 1){
                that.setData({
                  daren: res.data.daren,
                })
              } else if (res.data.tag == 3){
                that.setData({
                  fensi: res.data.fensi,
                })
              }
            },
            fail: function (err) {
              console.log("err" + err);
            }
          })
          that.data.darenlists[thisid].followFlag=false;
          that.setData({
            darenlists: that.data.darenlists
          })
          //请求接口，刷新数据
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

  /*************关注***************** */
  guanzhu:function(e){
    console.log(e);
      var that=this;
      var thisid=e.currentTarget.id;
      var tags = e.currentTarget.dataset.guanzhu;
      var zid = e.currentTarget.dataset.id;
      wx.request({
        url: 'https://www.jikecity.xin/small/my/' + tags,  //此tag是活的  
        data: {
          openid: app.globalData.openid,
          zid: zid,
        },
        method: "POST",
        header: {
          "Content-Type": "application/x-www-form-urlencoded" //post
        },
        success: function (res) {
            that.setData({
              fensi: res.data.fensi,
            })
        },
        fail: function (err) {
          console.log("err" + err);
        }
      })
  },

  //点击足迹进内页
  newsdetail:function(e){
    wx.navigateTo({
      url: '/pages/detail/detail?newid=' + e.currentTarget.dataset.id,
    })
  },
  /************点击进入我关注的达人/粉丝的内页（发布人的主页）******************** */
  publisher:function(e){
    
    wx.navigateTo({
      url: '/pages/publisher/publisher?publisherId=' + e.currentTarget.dataset.id,
    })
  },
  /*******点击进入视频文章详情*********** */
  audiodetail:function(e){
    wx.navigateTo({
      url: '/pages/audio/audio?newid=' + e.currentTarget.dataset.id,
    })
  },
  /*********点击申请播报号********** */
  apply:function(){
    wx.navigateTo({
      url: '/pages/apply/apply',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})